package com.example.demo;

import java.io.IOException;

public class HtmlToPdfConverter {
    public void convertHtmlToPdf(String inputHtmlUrl, String outputPdfPath) throws IOException, InterruptedException {
        // 在Windows环境下
        Process process = Runtime.getRuntime().exec("cmd /c wkhtmltopdf.exe " + inputHtmlUrl + " " + outputPdfPath);

        // 在Unix/Linux环境下（包括Mac）
        // Process process = Runtime.getRuntime().exec(new String[]{"wkhtmltopdf", inputHtmlUrl, outputPdfPath});

        // 等待进程结束并处理输出流和错误流（这里仅示例，实际应用中需确保正确读取和处理输出）
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            // 处理错误情况
            throw new RuntimeException("Failed to convert HTML to PDF");
        }
    }
}